﻿/**
 * GoText Palm: A program that allows to send text messages over the internet.
 *  Copyright (C) 2008 Nicola 'Gawaine' Racco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace GoTextPalm.Core.Localization.Reducer
{
    public class English : IRedCmd, IConvCmd
    {
        public String Reduce(ReduceLevel level, String text)
        {
            if (level >= ReduceLevel.L1)
                text = level1(text);
            if (level >= ReduceLevel.L2)
                text = level2(text);
            if (level >= ReduceLevel.L3)
                text = level3(text);
            if (level >= ReduceLevel.L4)
                text = level4(text);
            return text;
        }

        public String Convert(String text)
        {
            return text;
        }

        private String level1(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("One", "1");
            sb.Replace("one", "1");
            sb.Replace("two", "2");
            sb.Replace("Two", "2");
            sb.Replace("Three", "3");
            sb.Replace("three", "3");
            sb.Replace("Four", "4");
            sb.Replace("four", "4");
            sb.Replace("five", "5");
            sb.Replace("Five", "5");
            sb.Replace("six", "6");
            sb.Replace("Six", "6");
            sb.Replace("seven", "7");
            sb.Replace("Seven", "7");
            sb.Replace("Eight", "8");
            sb.Replace("eight", "8");
            sb.Replace("Nine", "9");
            sb.Replace("nine", "9");
            sb.Replace("Ten", "10");
            sb.Replace("Ten", "10");
            sb.Replace("  ", " ");
            sb.Replace("...", "..");
            sb.Replace("....", "..");
            sb.Replace(", ", ",");
            sb.Replace(". ", ".");
            sb.Replace("; ", ";");
            sb.Replace(": ", ":");
            sb.Replace("! ", "!");
            sb.Replace("? ", "?");
            return sb.ToString();
        }

        private String level2(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("too", "2");
            sb.Replace("Too", "2");
            sb.Replace("to", "2");
            sb.Replace("To", "2");
            sb.Replace("fore", "4");
            sb.Replace("Fore", "4");
            sb.Replace("for", "4");
            sb.Replace("For", "4");
            return sb.ToString();
        }

        private String level3(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("with", "w/");
            sb.Replace("without", "w/o");
            sb.Replace("something", "s/t");
            return sb.ToString();
        }

        private String level4(String text)
        {
            StringBuilder sb = new StringBuilder(text);
            sb.Replace("be", "b");
            sb.Replace("are", "r");
            sb.Replace("you", "u");
            sb.Replace("see", "c");
            sb.Replace("why", "y");
            return sb.ToString();
        }
    }
}
